﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Labo
{
    class Program2
    {
        public static void Main2()
        {
            var a = new Some();
            a.Set("Text","Hello");
            Console.WriteLine(a.Get("Text"));
            Console.ReadLine();
        }
    }

    class Base
    {
        // Type -> Property -> PropertyType * DefaultValue
        public static Dictionary<Type,Dictionary<string,Tuple<Type,object>>> Meta = new Dictionary<Type, Dictionary<string, Tuple<Type, object>>>();
        
        public Dictionary<string,object> Dict = new Dictionary<string, object>();

        public static void RegisterType(Type self)
        {
            Meta.Add(self,new Dictionary<string, Tuple<Type, object>>());
        }

        public static void RegisterType(Type self,Type parent)
        {
            if(!Meta.ContainsKey(self))
                Meta.Add(self,new Dictionary<string, Tuple<Type, object>>());

            foreach (var prop in Meta[parent])
            {
                Meta[self].Add(prop.Key,prop.Value);
            }
        }

        public static void RegisterProp(Type type,string prop,Type ty,object value)
        {
            Meta[type][prop] = new Tuple<Type, object>(ty,value);
        }

        public void RegisterProp(string prop,Type ty,object value)
        {
            Meta[this.GetType()][prop] = new Tuple<Type, object>(ty,value);
        }

        public object Get(string name)
        {
            //if(Meta[this.GetType()].ContainsKey(name))
            //    return Dict[name];
            //else
            //    return "fuck";

            if(Dict.ContainsKey(name))
                return Dict[name];
            else
                return null;
        }

        public void Set(string name,object value)
        {
            //if(Meta[this.GetType()].ContainsKey(name))
            //    Dict[name] = value;

            Dict[name] = value;
        }
    }

    class Some : Base
    {
        static Some()
        {
            RegisterType(typeof (Some));
            RegisterProp(typeof(Some),"Text",typeof(string),"");
        }
    }


}
